/**
 * @author yuliang
 *
 */
package com.xuhai.libms.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xuhai.libms.dao.UserTypeDao;
import com.xuhai.libms.entity.UserType;

public class UserTypeDaoImpl extends HibernateDaoSupport implements UserTypeDao {

	public void remove(UserType userType) {
		super.getHibernateTemplate().delete(userType);
	}

	public void insert(UserType userType) {
		super.getHibernateTemplate().save(userType);
	}

	public void modify(UserType userType) {
		super.getHibernateTemplate().saveOrUpdate(userType);
	}

	public UserType show(int id) {
		return (UserType)super.getHibernateTemplate().get(UserType.class, id);
	}
	public List<UserType> show() {
		return (List)super.getHibernateTemplate().find("from UserType");
	}

	public List<UserType> showByPage(UserType userType,int start,int end) {
		List<UserType> list = null;
		if(userType.getType_name()!=null&&userType.getType_name()!=""){
			String type_name = userType.getType_name();
			String sql = "from UserType u where u.type_name=:type_name";
			 list = getHibernateTemplate().findByNamedParam(sql, "type_name", type_name).subList(start, end);
		}else{
			 list = getHibernateTemplate().find("from UserType").subList(start, end);
		}
		return list;
	}

	public int getSize(UserType userType) {
		if(userType.getType_name()!=null&&userType.getType_name()!=""){
			String type_name = userType.getType_name();
			String sql = "from UserType u where u.type_name=:type_name";
			 return getHibernateTemplate().findByNamedParam(sql, "type_name", type_name).size();
		}else{
			 return getHibernateTemplate().find("from UserType").size();
		}
	}
}
